import sys
from PyQt5.QtWidgets import (
    QVBoxLayout, QToolTip, QMessageBox,
    QPushButton, QLabel, QWidget, QDialog,
    QApplication, QLineEdit, QFormLayout
)

from PyQt5.QtGui import QPalette, QColor, QPixmap, QIntValidator, QDoubleValidator
from PyQt5.QtCore import Qt

class MyWidget(QWidget):
    def __init__(self, parent=None):
        super(MyWidget, self).__init__(parent)
        self.initUI()

    def initUI(self):
        
        self.setGeometry(300, 300, 600, 600)#设置窗口位置和大小
        self.setWindowTitle('QWidget 实例')#设置窗口标题
        
        formLayout = QFormLayout()#创建一个form layout
        
        pIpLineEdit = QLineEdit(self)
        pMacLineEdit = QLineEdit(self)
        pDataLineEdit = QLineEdit(self)
        pLincenseLineEdit = QLineEdit(self)

        # pIpLineEdit.setInputMask("000.000.000.000")#设置IP地址掩码
        # pMacLineEdit.setInputMask("HH:HH:HH:HH:HH:HH")#设置MAC地址掩码
        # pDataLineEdit.setInputMask("0000-00-00")#设置日期掩码
        # pLincenseLineEdit.setInputMask("AAAAA-AAAAA-AAAAA-AAAAA-AAAAA")#设置许可证掩码
        
        pIpLineEdit.setInputMask("000.000.000.000;_")#设置IP地址掩码
        pMacLineEdit.setInputMask("HH:HH:HH:HH:HH:HH;_")#设置MAC地址掩码
        pDataLineEdit.setInputMask("0000-00-00")#设置日期掩码
        pLincenseLineEdit.setInputMask("AAAAA-AAAAA-AAAAA-AAAAA-AAAAA;#")#设置许可证掩码

        formLayout.addRow("IP地址", pIpLineEdit)
        formLayout.addRow("MAC地址", pMacLineEdit)
        formLayout.addRow("日期", pDataLineEdit)
        formLayout.addRow("许可证", pLincenseLineEdit)

        self.setLayout(formLayout)#设置窗口布局


def main():
    app = QApplication(sys.argv)
    w = MyWidget()
    w.show()
    sys.exit(app.exec_())
    
    
if __name__ == "__main__":
    main()
